/*
 * ImportDeskWidget.fx
 *
 * Created on 11-Feb-2009, 23:20:30
 */

package widgets;

import javafx.scene.CustomNode;
import javafx.scene.Group;
import javafx.scene.Node;
import javafx.scene.shape.Rectangle;
import javafx.scene.paint.Color;
import javafx.animation.Timeline;
import javafx.animation.KeyFrame;
import javafx.animation.Interpolator;
import javafx.scene.text.Text;
import javafx.ext.swing.SwingLabel;
import javafx.ext.swing.SwingHorizontalAlignment;
import javafx.scene.text.Font;
import javafx.scene.image.ImageView;
import javafx.scene.image.Image;
import logic.Importer;

/**
 * @author beol
 */

public class ImportDeskWidget extends CustomNode {

    public var x: Number = 100;
    public var y: Number = 100;

    public function setStateConnecting() {
        state = "соединяюсь с сервером"
    }
    
    public function setStateConnectionError() {
        state = "сервер недоступен"
    }
    
    public function setStateError() {
        state = "ошибка ввода"
    }
    
    public function setStateProcessingResponse() {
        state = "обработка данных"
    }

    var state: String = "42";

    var background: Rectangle = Rectangle {
        x: x,
        y: y,
        width: 220,
        height: 220
        fill: Color.LIGHTGRAY
        stroke: Color.BLACK
        strokeWidth: 1
        arcWidth: 30
        arcHeight: 30
    }

    var stateBackground: Rectangle = Rectangle {
        translateX: x + 12;
        translateY: y + 10;
        width: 197
        height: 24
        fill: Color.WHITE
        arcWidth: 10
        arcHeight: 10
    }


    var stateText: SwingLabel = SwingLabel {
        translateX: x
        translateY: y + 14
        font: Font {
            size: 12
        }
        horizontalAlignment: SwingHorizontalAlignment.CENTER;
        text: bind state
        width: 180
    }

    def rotateValue: Number = 0;

    def imageProccess: ImageView = ImageView {
        image: Image {
            url: "{__DIR__}process.png"
        }
        translateY: y - 2
        translateX: x + 170
        scaleX: 0.5
        scaleY: 0.5
        rotate: bind rotateValue
    }

    def rotateAnimation: Timeline = Timeline {
        repeatCount: Timeline.INDEFINITE
        rate: 1
        keyFrames: [
            KeyFrame {
                time: 0s
                values: rotateValue => 0.0
            },
            KeyFrame {
                time: 3s
                values: rotateValue => -360.0 tween Interpolator.LINEAR;
            }
        ]
    }

    var node: Group = Group {

    }


    protected override function create(): Node {
        setStateConnecting();
        rotateAnimation.play();
        node.content = [background, stateBackground, stateText, imageProccess];
        return node;
    }
}
